import ruleOpt from '@/biz/option/rule.js'
let _this = null

function disabledDate(date, disabledDate) {
  let start = disabledDate ? disabledDate.split(' ')[0] : null
  let end = Date.now()
  return date && (date.valueOf() < Date.parse(start) - 86400000 || date.valueOf() > end)
}
//设置组长
function part1() {
  return [
  {
    title: '生效日期',
    key: 'upDate',
    placeholder: '请选择生效日期',
    date: {
      type: 'date',
      disabled: (date) => disabledDate(date)
    },
    rules: [ruleOpt.required('请选择生效日期')]
  }]
}
//取消组长
function part2() {
  return [
  {
    title: '组长起始日期',
    key: 'takeEffectDate',
    text: {},
    data: {
      from: (info) => {
        return info.takeEffectDate ? info.takeEffectDate.split(' ')[0] : '-'
      }
    }
  },
  {
    title: '取消日期',
    key: 'cancelDate',
    placeholder: '请选择取消日期',
    date: {
      type: 'date',
      disabled: (date) => disabledDate(date, _this.info.takeEffectDate)
    },
    rules: [ruleOpt.required('请选择取消日期')]
  }]
}
//移出小组
function part3() {
  return [
  {
    title: '入组日期',
    key: 'inGroupDate',
    text: { show: 'false' },
    data: {
      from: (info) => {
        return info.inGroupDate ? info.inGroupDate.split(' ')[0] : '-'
      }
    }
  },
  {
    title: '离组日期',
    key: 'outGroupDate',
    placeholder: '请选择离组日期',
    date: {
      type: 'date',
      disabled: (date) => disabledDate(date, _this.info.inGroupDate)
    },
    rules: [ruleOpt.required('请选择离组日期')]
  }]
}

function options(vm) {
  _this = vm
  let p1 = part1()
  let p2 = part2()
  let p3 = part3()
  let arr = [{
    title: '姓名',
    key: 'userName',
    text: {}
  }, ]
  if (_this.modelType == 'set') {
    arr.push(...p1)
  } else if (_this.modelType == 'cancel') {
    arr.push(...p2)
  } else if (_this.modelType == 'remove') {
    arr.push(...p3)
  }
  return arr
}

export default {
  options
}